import { QueryTypes } from "@sequelize/core";
import { Column, Table } from "../../model/schema";
import { QuerySchema } from "../QuerySchema";

export class MySQLSchema extends QuerySchema{
    
    constructor(){
        super('mysql');
        this.tablesSql = "show table status WHERE 1=1";
        this.tableFieldsSql = "show full fields from %s";
        this.tableName = "Name";
        this.tableComment = "Comment";
        this.fieldName = "Field";
        this.fieldType = "Type";
        this.fieldComment = "Comment";
        this.fieldKey = "Key";
        this.fieldDefaultValue = "Default";
    }

    parseTableFromDB(tableInfo){
        return new Table(tableInfo[this.tableName], tableInfo[this.tableComment]);
    }
    parseColumnFromDB({Field, Type, Null, Key, Default, Comment}){
        return new Column(
            Field,
            Type,
            Default,
            Key.indexOf('PRI') > -1,
            Key.indexOf('UNI') > -1,
            Null.indexOf('NO') > -1,
            Comment
        )
    }


}